package com.peanut.baby.model;


import com.peanut.devlibrary.util.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;


public class AuthrizeInfo {

    public static final int TYPE_WEIXIN = 2;
    public static final int TYPE_QQ = 1;
    public static final int TYPE_WEIBO = 3;

    public String openId = "";
    public String accessToken = "";
    public long             expireIn = 0;
    public int              type = TYPE_WEIXIN;
    public String dataSource = "app";

    //设备参数
    public String uuid = "";
    public String idfa = "";
    public String mac = "";
    public String ipAddress = "";

    public String device = "android";
    public String osversion = "";
    public String model = "";
    public String version = "";
   public String screen = "";
   public String network = "";

   public String nickname = "";
    public String avatar = "";
    public String gender = "";
    public String province = "";
    public String city = "";
    public String country = "";
    public String unionid = "";
    public AuthrizeInfo(){}
    public AuthrizeInfo(JSONObject obj){
        if(obj == null){
            return;
        }

        try {
            openId = JsonUtils.JSONString(obj,"openid");
            accessToken = JsonUtils.JSONString(obj,"accesstoken");
            nickname = JsonUtils.JSONString(obj,"nickname");
            avatar =  JsonUtils.JSONString(obj,"avatar");
            gender = JsonUtils.JSONString(obj,"gender");
            province = JsonUtils.JSONString(obj,"province");
            city = JsonUtils.JSONString(obj,"city");
            country = JsonUtils.JSONString(obj,"country");
            unionid = JsonUtils.JSONString(obj,"unionid");

            dataSource = JsonUtils.JSONString(obj,"dataSource");
            type = JsonUtils.JSONInter(obj,"type");
            expireIn = JsonUtils.JSONLong(obj,"expiresIn");
        } catch (JSONException e) {

        }


    }

    public JSONObject toJson(){
        JSONObject data = new JSONObject();
        try {
            data.put("openid",openId);
            data.put("accesstoken",accessToken);
            data.put("expiresIn",expireIn);
            data.put("type",type);
            data.put("dataSource",dataSource);
            data.put("nickname", nickname);
            data.put("avatar",avatar);
            data.put("avatar", avatar);
            data.put("gender", gender);
            data.put("province",province);
            data.put("city", city);
            data.put("country",country);
            data.put("unionid",unionid);
        } catch (JSONException e) {

        }
        return data;
    }

    @Override
    public String toString() {
        return "AuthrizeInfo{" +
                "openId='" + openId + '\'' +
                ", accessToken='" + accessToken + '\'' +
                ", expireIn=" + expireIn +
                ", type=" + type +
                ", dataSource='" + dataSource + '\'' +
                ", uuid='" + uuid + '\'' +
                ", idfa='" + idfa + '\'' +
                ", mac='" + mac + '\'' +
                ", ipAddress='" + ipAddress + '\'' +
                ", device='" + device + '\'' +
                ", osversion='" + osversion + '\'' +
                ", model='" + model + '\'' +
                ", version='" + version + '\'' +
                ", screen='" + screen + '\'' +
                ", network='" + network + '\'' +
                ", nickname='" + nickname + '\'' +
                ", avatar='" + avatar + '\'' +
                ", gender='" + gender + '\'' +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", country='" + country + '\'' +
                ", unionid='" + unionid + '\'' +
                '}';
    }
}
